﻿@{
    Layout = "../_QuickLayoutPage.cshtml";
    IEnumerable<dynamic> canRegMemberGroupList = ViewBag.CanRegMemberGroupList;
    int defaultMemberGroupId = (int)ViewBag.DefaultMemberGroupId; //默认会员组id
    string guid = Html.Guid();
    string beforeSubmitJs = "";
}
<div class="login-sign">会员注册</div>
<div id="regBox">
  <form method="post" id="regForm" data-validate-params="beforeSubmit:'BeforeSubmit',tipsStyle:1" class="form" autocomplete="off">
                        <div class="validate-all-tips-box"></div>
                        @if (canRegMemberGroupList.Count() > 1)
                        {

                            <div class="form-group">
                                <label class="control-label">注册类型*</label>
                                <div class="controls ">
                                    <select class="form-control" id="_regmemberGroup" name="_regmemberGroup">
                                        @foreach (dynamic memberGroup in canRegMemberGroupList)
                                        {
                                            int memberGroupId = memberGroup.Id;
                                            <option value="@memberGroupId" data-url="@Url.Action("index",new { id = memberGroupId,area="Member" })">@memberGroup.Name</option>
                                        }
                                    </select>
                                    <span class="help-block"></span>
                                </div>
                            </div>
                            <script type="text/javascript">
                            var $regmemberGroup = $("#_regmemberGroup");
                            $regmemberGroup.on("change", function () {
                                location.href = $(this).children("option:selected").attr("data-url");
                            });
                            $regmemberGroup.SetSelected("@ViewBag.DefaultMemberGroupId");
                            </script>
                        }

                        <div class="form-group">
                            <label class="control-label">用户名*</label>
                            <div class="controls ">
                                <input type="text" id="username" name="username" class="form-control" maxlength="15" placeholder="用户名" data-validate="dataType:'username',nullMsg:'请填写用户名',errorMsg:'',checkUrl:'@Url.Action("CheckUserName","CheckRepeate",new {id=Request.QueryString["id"],area = "E" })',checkError:'此用户名已经被注册，请重新填写'">
                                <span class="help-block"></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="control-label">密码*</label>
                            <div class="controls">
                                <input type="password" id="password" name="password" class="form-control ui-passwordEye" maxlength="15" placeholder="密码" data-validate="dataType:'password',nullMsg:'请填写密码',errorMsg:''">
                                <span class="help-block"></span>
                            </div>
                        </div>

                        @if (ViewBag.MobileFieldSet == "1" || ViewBag.MobileFieldSet == "2")
                        {
                            <div class="form-group">
                                <label class="control-label">手机*</label>
                                <div class="controls">
                                    <input type="text" id="mobile" name="mobile" class="form-control" maxlength="15" placeholder="手机号码" data-validate="dataType:'mobile',nullMsg:'请填写手机号码',errorMsg:'手机号码格式错误'@if(ViewBag.MobileOnlyOne =="1"){<text>,checkUrl: '@Url.Action("CheckRegMobile","CheckRepeate",new {id=Request.QueryString["id"],area = "E" })',checkError: '此手机号已经被注册'</text>}">
                                    <span class="help-block"></span>
                                </div>
                            </div>

                        }
                        @if (ViewBag.MobileFieldSet == "2")
                        {
                            <div class="form-group">
                                <label class="control-label">手机验证码*</label>
                                <div class="controls">
                                    <div class="input-group clearfix">
                                        <input type="text" id="_SmsCode" name="_SmsCode" class="form-control" maxlength="6" placeholder="点击右侧按钮获取手机验证码" data-validate="dataType:'numeric',minLength:6,minLengthErrorMsg:'手机验证码为6位数字！',nullMsg:'请填写手机验证码！',checkUrl:'/E/SmsCode/Validate',checkError:'手机验证码填写错误',additionals:'#mobile'">
                                        <span class="input-group-btn">
                                            <button type="button" class="btn btn-primary ui-btn-sendCode" data-send-params="type:'mobile',accordingObj:'#mobile'">获取验证码</button>
                                        </span>
                                    </div>
                                    <span class="help-block"></span>
                                </div>
                            </div>
                        }
                        @if (ViewBag.EmailFieldSet == "1" || ViewBag.EmailFieldSet == "2")
                        {
                            <div class="form-group">
                                <label class="control-label">邮箱*</label>
                                <div class="controls">
                                    <input type="text" id="email" name="email" class="form-control" maxlength="30" placeholder="邮箱地址" data-validate="dataType:'email',nullMsg:'请填写邮箱地址',errorMsg:'邮箱地址格式错误！'@if (ViewBag.EmailOnlyOne == "1") {<text>,checkUrl:'@Url.Action("CheckRegEmail", "CheckRepeate", new { id = Request.QueryString["id"], area = "E" })',checkError:'此邮箱已经被注册'</text>} ">
                                    <span class="help-block"></span>
                                </div>
                            </div>
                        }
                        @if (ViewBag.EmailFieldSet == "2")
                        {
                            <div class="form-group">
                                <label class="control-label">邮件验证码*</label>
                                <div class="controls">
                                    <div class="input-group clearfix">
                                        <input type="text" id="_EmailCode" name="_EmailCode" class="form-control" maxlength="6" placeholder="点击右侧按钮获取邮件验证码" data-validate="dataType:'numeric',minLength:6,minLengthErrorMsg:'邮件验证码为6位数字！',nullMsg:'请填写邮件验证码',checkUrl:'/E/EmailCode/Validate',checkError:'邮件验证码填写错误',additionals:'#email'">
                                        <span class="input-group-btn">
                                            <button type="button" class="btn btn-primary ui-btn-sendCode" data-send-params="type:'email',accordingObj:'#email'">获取验证码</button>
                                        </span>
                                    </div>
                                    <span class="help-block"></span>
                                </div>
                            </div>
                        }

                        @{

                            var data = new ViewDataDictionary();
                            data.Add("from", "member");
                            data.Add("guid", guid);
                            data.Add("currentUser", null);
                            data.Add("memberGroupId", ViewBag.DefaultMemberGroupId);
                            data.Add("i", 0);
                            IEnumerable<dynamic> FieldData = ViewBag.FieldData;
                            int i = 0;
                            if (FieldData != null)
                            {
                                foreach (var row in FieldData)
                                {
                                    data["i"] = i;
                                    beforeSubmitJs += row.BeforeSubmitJs;
                                    Html.RenderPartial("~/Areas/E/Views/CustomForm/FormPartial.cshtml", (object)row, data);
                                    i++;
                                }
                            }

                        }

                        @if (ViewBag.VerificationCode == "1")
                        {
                            <div class="form-group">
                                <label class="control-label">验证码*</label>
                                <div class="controls">
                                    <div class="input-group">
                                        <input type="text" id="_VerificationCode" name="_VerificationCode" class="form-control" maxlength="4" placeholder="输入右侧的验证码" data-validate="dataType:'*',minLength:4,minLengthErrorMsg:'验证码最少4个字符',nullMsg:'请填写验证码',checkUrl:'/E/VerificationCode/Validate',checkError:'验证码填写错误'">
                                        <span class="input-group-btn">
                                            <a class="btn btn-default btn-verificationCodeImg"><img id="verificationCodeImg" src="/E/VerificationCode/?width=100&height=39" class="ui-verificationCodeImage" /></a>
                                        </span>
                                    </div>
                                    <span class="help-block" id="_ValidateTips__VerificationCode"></span>
                                </div>
                            </div>
                        }

                        <div class="form-group">
                            <div class="controls">
                                <input id="agreement" name="agreement" type="checkbox" value="1" data-validate="dataType:'*',nullMsg:'必须阅读并同意用户注册协议'" checked> <label for="agreement" class="text-muted font-normal">&nbsp;已阅读并同意<a href="@Url.ActionUrl("RegAgreement")" target="_blank" class="blue">《用户注册协议》</a></label>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="controls">
                                @Html.AntiForgeryToken()
                                <input type="hidden" id="guid" name="guid" value="@guid" />
                                <input type="hidden" id="memberGroupId" name="memberGroupId" value="@ViewBag.DefaultMemberGroupId" />
                                <button type="button" class="btn  btn-primary btn-lg col-xs-12 col-md-12  ui-pagePost" data-custom-params="url:'@Url.ActionUrl("Index")',callBack:'LoginSuccess',successMsg:''">注册</button>
                            </div>
                        </div>

                        <div class="text-center">
                            已有账户？<a href="@Url.ActionUrl("Quick","Login")" class="text-primary">去登录</a>
                        </div>

                    </form>
</div>
    <script type="text/javascript">

    var open = @ViewBag.Open;
     var $username = $("#username");
    var $regBox = $("#regBox");
    if (open == 0)
    {
        $regBox.html("对不起，网站注册功能已关闭!")
    }
    var $form = $("#regForm");
    var $verificationCode = $("#verificationCode");
    $verificationCode.val("");

    function BeforeSubmit() {
         @Html.Raw(beforeSubmitJs)
        return true;
    }

   function LoginSuccess(result)
    {
       layer.msg('注册成功,转到登录页面..', {
                icon: 16,
                time: 1500, //1秒
                shade: 0.1
       }, function () {
           if (typeof (parent.RegSuccess) == "function") {
               parent.RegSuccess(result);
           }
           else
           {
             location.href="@Url.ActionUrl("Quick","Login")";
           }
       });
    }

         $(function () { AutoDialog(); })
         $(document).keyup(function (event) {
             if (event.keyCode == 13) {
                 $(".ui-pagePost").trigger("click");
             }
         });
    </script>
